﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Accountant.DataModel;

namespace Perf
{
  class Program
  {
    static void Main(string[] args)
    {
      Database.SetInitializer(new DbInitializer());
      var ctx = new AccountantContext();
      ctx.Database.Delete();
      ctx.Load();
      var g = new RandomDataGenerator(ctx, 0);
      g.Run(2000000, new DateTime(2000, 5, 12));
      Write(ctx);

      Console.WriteLine("Size: " + ctx.Database.GetSize());
      ctx.Accounts.Clear();
      ctx.Currencies.Clear();
      ctx.Transactions.Clear();
      Read(ctx);
    }

    private static void Read(AccountantContext ctx)
    {
      var stopwatch2 = Stopwatch.StartNew();
      ctx.Load(); // Now load real data
      stopwatch2.Stop();
      Console.WriteLine("Read time: " + stopwatch2.Elapsed);
    }

    private static void Write(AccountantContext ctx)
    {
      var stopwatch = Stopwatch.StartNew();
      ctx.SaveChanges();
      stopwatch.Stop();
      Console.WriteLine("Write time: " + stopwatch.Elapsed);
    }
  }
}
